package 快排;

/**
 * @author wtcode
 * @date 2021/3/8 - 21:26
 */
public class QuickSort {

    public static void sort(int[] a) {
        if (a.length > 0) {
            sort(a, 0, a.length - 1);
        }
    }

    public static void sort(int[] a, int l, int r)  {
        int i = l;
        int j = r;
        int pivot = a[l];
        while(i < j){

            while(i < j && a[j] > pivot){
                j--;
            }
            while (i < j && a[i] >= pivot){
                i++;
            }

            if(i < j){
                int temp = a[i];
                a[i] = a[j];
                a[j] = temp;

            }
        }
        pivot = a[i];
        a[i] = a[l];
        a[l] = pivot;
    }


}
